<template>
  <div>
    <!-- 进度条 -->
    <br />
    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安 全 等 级:
    <div style="margin-top: -20px;margin-left: 140px;width:200px;">
      <el-progress :percentage="70" :stroke-width="13" :format="format"></el-progress>
    </div>
    <br />
    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    登 录 密 码：安全性高的密码可以使账号更安全。建议您定期更换密码，
    <br />
    <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;且设置一个长度超过6位以上的密码。
    <div style="margin-top: -63px;margin-left: 600px;">
      <el-button type="warning" size="mini" icon="el-icon-setting" @click="updateFlag">修 改</el-button>
    </div>
    <!-- Form -->
    <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="ruleForm.username" autocomplete="off" readonly></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth" prop="password">
          <el-input v-model="ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="updatePassword('ruleForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
var quan;
export default {
  name: "app",
  data() {
    return {
      dialogFormVisible: false,
      ruleForm: {
        username: localStorage.getItem("username"),
        password: ""
      },
      formLabelWidth: "120px",
      rules: {
        password: [
          { required: true, message: "密码不能为空!", trigger: "blur" },
          { min: 6, max: 10, message: "长度在 6 到 10 个字符", trigger: "blur" }
        ]
      }
    };
  },
  mounted: function() {
    quan = this;
  },
  methods: {
    format(percentage) {
      return percentage === 100 ? "满" : `${percentage}%`;
    },
    updateFlag: function() {
      quan.dialogFormVisible = true;
    },
    updatePassword(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          quan.axios
            .get("http://localhost:9999/basic/tmsCompany/updatePassword", {
              params: {
                access_token: localStorage.getItem("access_token"),
                password: quan.ruleForm.password,
                username: localStorage.getItem("username")
              }
            })
            .then(function(res) {
              quan.$message({
                message: res.data.msg,
                type: "success"
              });
              if (res.data.code == 200) {
                quan.dialogFormVisible = false;
                quan.password = "";
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>